package com.cskaoyan.javase._2polymorphic._2advantage.conversion;

/**
 * 研究向下转型成功的条件
 * 强转能够运行成功的前提是:
 * 父类引用指向的对象
 * 是要强转成的引用的数据类型的对象
 * 或者是要强转成的引用的数据类型的子类对象
 *
 * 总之,要想强转成功,
 * 强转后的引用必须是真的能够指向这个对象
 *
 * @since 16:38
 * @author wuguidong@cskaoyan.onaliyun.com
 */
public class Demo {
    public static void main(String[] args) {
        Grandfather gf = new Grandson();
        Father f = (Father) gf;
        Son s = (Son) gf;
        Grandson gs = (Grandson) gf;


        Grandfather gf2 = new Son();
        Son s2 = (Son) gf2;
        Father f2 = (Father) gf2;
        // Grandson gs2 = (Grandson) gf2;
    }
}

class Grandfather {
}

class Father extends Grandfather {
}

class Son extends Father {
}

class Grandson extends Son {
}